<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="../../tag/c.tld"%>
<!DOCTYPE html>
<html lang="en">
<head>

<title>添加配置</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="../css/bootstrap.css" />
<link rel="stylesheet" href="../css/font-awesome.css" />

<link rel="stylesheet" href="../css/jquery-ui.css" />
<link rel="stylesheet" href="../css/datepicker.css" />

<link rel="stylesheet" href="../css/ace-fonts.css" />

<link rel="stylesheet" href="../css/ace.css" />
<link href="../css/fileinput.css" media="all" rel="stylesheet"
	type="text/css" />
<!-- ie9 -->
<link rel="stylesheet" href="../css/ace-part2.css" />
<link rel="stylesheet" href="../css/ace-ie.css" />

<script src="../js/jquery.js"></script>
<script src='../js/ace/jquery.mobile.custom.js'></script>
<script src="../js/ace/bootstrap.js"></script>

<script src="../js/ace/ace/ace.js"></script>
<script src="../js/ace/ace/ace.sidebar.js"></script>
<script src="../js/fileinput.js" type="text/javascript"></script>
<script src="../js/fileinput_locale_zh.js" type="text/javascript"></script>
</head>
<body class=" no-skin">
	<jsp:include page="../../margin/head.jsp"></jsp:include>
	<div class="main-container" id="main-container">
		<jsp:include page="../../margin/left.jsp"></jsp:include>
		<div class="main-content">
			<!-- 导航菜单 -->
			<div class="breadcrumbs" id="breadcrumbs">
				<ul class="breadcrumb">
					<li><i class="ace-icon fa fa-home home-icon"></i> <a
						href="/HuaJi/setting/list">Home</a></li>
					<li><a href="${pageContext.request.contextPath}/setting/list">配置</a></li>
					<li class="active">添加配置</li>
				</ul>
			</div>
			<div class="row">
				<div class="col-sm-12">
					<div class="widget-box">
						<div class="widget-header">
							<h4>添加配置</h4>
						</div>
						<div class="widget-body">
							<div class="widget-main no-padding">
								<form class="form-horizontal" action="${pageContext.request.contextPath}/setting/save"
									method="post" enctype="multipart/form-data" id="sysUserForm">
									<input type="hidden" name="userId" value="${setting.sid}">
									
									<div class="form-group">
										<label class="col-sm-3 control-label">类型：</label>
										<div class="col-sm-4">
											<select class="control-label col-sm-12" id = "typeid" onchange="changeType()" name = "type">
												<option value="1">品牌</option>
												<option value="2">产地</option>
												<option value="3">型号</option>
												<option value="4">系统</option>
												<option value="5">故障描述</option>
												<option value="6">维修类型</option>
												<option value="7">app配置</option>			
												<option value="8">评价标签</option>
											</select>
										</div>
									</div>
									
									<div class="form-group">
										<label class="col-sm-3 control-label">子类型：</label>
										<div class="col-sm-4">
											<select class="control-label col-sm-12" id = "cfieldId" name = "cfield">
												<option value="0">无</option>
												<c:forEach items="${sets}" var="item">
													<option value="${item.sid}">${item.name}</option>
												</c:forEach>
											</select>
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-3 control-label">名称：</label>
										<div class="col-sm-4">
											<input class="form-control" id="s_name" name="name"
												required="required" value="${setting.name}" type="text"
												placeholder="请输入名称" />
										</div>
									</div>
									
									<div class="form-group">
											<label class="col-sm-3 control-label">图标：</label>

											<div class="ol-lg-6 col-xs-6 col-sm-6" id="setingImg">
												<input class="file btn btn-sm btn-grey" type="file"
													name="setingImg">
											</div>
										</div>

									<div class="form-actions center">
										<button type="button" class="btn btn-sm btn-grey"
											id="go_back_btn" onclick="returnList()">
											返回 <i class="icon-reply icon-on-right bigger-110"></i>
										</button>
										<button type="submit" onclick="check()"
											class="btn btn-sm btn-success" id="save_btn">
											保存 <i class="icon-save icon-on-right bigger-110"></i>
										</button>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		$(".flowSta").addClass("active open");
		$(".regionSta").addClass("active");
	});

	function check() {
		var type = $("#type").val();
		var name = $("#name").val();
		$.ajax({
			type : 'post',
			url : '/HuaJi/user/check',
			dataType : "json",
			data : {
				type : type,
				name : name
			},
			success : function(data) {
				if (data.data) {
					$("#sysUserForm").submit();
				} else {
					$("#accountCheck").html("配置重复");
				}
			}
		});
	}
	
	function changeType(){
		var type = $("#typeid").val();
		$("#cfieldId").empty();
		$.ajax({
			type : 'post',
			url : '${pageContext.request.contextPath}/setting/changeType',
			dataType : "json",
			data : {
				type : type
			},
			success : function(data) {
				if (data.jData!='') {
					$("#cfieldId").append("<option value='0'>无</option>"); 
					for(var i=0;i<data.jData.length;i++){
						$("#cfieldId").append("<option value='" + data.jData[i].sid + "'>" + data.jData[i].name + "</option>"); 
					}
				}else{
					$("#cfieldId").append("<option value='0'>无</option>"); 
				}
			}
		});
	}

	function returnList() {
		window.location = "${pageContext.request.contextPath}/setting/list";
	}
</script>
</html>
